//
//  XXSPInfoViewController.m
//  ShangChengMoBan
//
//  Created by 张铁军 on 16/8/29.
//  Copyright © 2016年 ping. All rights reserved.
//

#import "XXSPInfoViewController.h"
#import "SDCycleScrollView.h"
#import "XXSP_ShouYeView.h"
#import "ImageWithLabelView.h"
#import "XXSPshopViewController.h"

@interface XXSPInfoViewController ()<UIScrollViewDelegate,SDCycleScrollViewDelegate,UIWebViewDelegate,XXSPDelegate>
{
    UIScrollView *_myScrollView;
    SDCycleScrollView *_myTopScrollView;
    XXSP_ShouYeView *_chanPinInfoView;
    UIWebView *_myWebView;
   
}
@end

@implementation XXSPInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self drawView];
    [self drawBackButton];
}


-(void)drawView{
    _myScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    _myScrollView.backgroundColor = LIGHTGRAYBACKCOLOR;
    [self.view addSubview:_myScrollView];
    _myTopScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, KScreenWidth, 170 * _kscH)imageURLStringsGroup:nil];
    
    _myTopScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    _myTopScrollView.delegate = self;
    _myTopScrollView.autoScrollTimeInterval = 3;
    _myTopScrollView.imageURLStringsGroup = _firstModel.lunboImgURL;
    _myTopScrollView.tag = 0;
    
    _myTopScrollView.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
    _myTopScrollView.placeholderImage = [UIImage imageNamed:PLaceHolderImage];
    [_myScrollView addSubview:_myTopScrollView];
    
    _chanPinInfoView = [[XXSP_ShouYeView alloc]initWithFrame:CGRectMake(0,_myTopScrollView.bottom, KScreenWidth, 80)];
    _chanPinInfoView.delegate = self;
    _chanPinInfoView.nameLabel.text = _firstModel.shopName;//商品名称
    _chanPinInfoView.diDianLabel.text = _firstModel.province;//地址
    [_myScrollView addSubview:_chanPinInfoView];
    
    ImageWithLabelView *xiangQingLabel = [[ImageWithLabelView alloc]initWithFrame:CGRectMake(0, _chanPinInfoView.bottom + 20, KScreenWidth, 35)];
    xiangQingLabel.nameLabel.text = @"店铺详情";
    [_myScrollView addSubview:xiangQingLabel];
    
    _myWebView = [[UIWebView alloc]initWithFrame:CGRectMake(0, xiangQingLabel.bottom,KScreenWidth, 100)];
    _myWebView.delegate = self;
    _myWebView.scrollView.scrollEnabled = NO;
    [_myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.baidu.com"]]];
    [_myScrollView addSubview:_myWebView];
    
    
}

-(void)buyClicked{
    XXSPshopViewController * buyView = [[XXSPshopViewController alloc]init];
    buyView.firstModel = _firstModel;
    [self.navigationController pushViewController:buyView animated:YES];
}

-(void)drawBackButton{
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(10, 20, 60, 44)];
    
    [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchDown];
    BaseLabel *backLabel = [[BaseLabel alloc]initWithFrame:CGRectMake( 20, 5, 40, 34)];
    backLabel.myfont = TITLEFONT;
    
    //35  52
    UIImageView *btnImage = [[UIImageView alloc]initWithFrame:CGRectMake(8, 5, 30 ,30)];
    [btnImage setImage:[UIImage imageNamed:@"返回"]];
    [btn addSubview:btnImage];
    //    [btn addSubview:backLabel];
    [self.view addSubview:btn];
}

-(void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark scrollViewDelegate
-(void)webViewDidFinishLoad:(UIWebView *)webView{
    CGRect frame = webView.frame;
    frame.size.height = 1;
    webView.frame = frame;
    //自适应
    CGSize fittingSize = [webView sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    
    if (frame.size.height != 1) {
        _myWebView.frame = frame;
        _myScrollView.contentSize = CGSizeMake(KScreenWidth, _myWebView.bottom);

    }

    
}
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
